#include<stack>
#include<string>
#include<iostream>
using namespace std;
string decodeString(string s) {
    int cur = 0;
    stack<char> digit;
    stack<string> letter;
    letter.push("");
    while (cur < s.size()) {
        if (s[cur] >= '0' && s[cur] <= '9') {
            digit.push(s[cur]);
            cur++;
        }
        else if (s[cur] == '[') {
            cur++;
            letter.push("");
            while (s[cur] >= 'a' && s[cur] <= 'z')
                letter.top() += s[cur++];
        }
        else if (s[cur] == ']') {
            string s;
            int x = digit.top();
            while (x--)
                s += letter.top();
            digit.pop();
            letter.pop();
            letter.top() += s;
            cur++;
        }
        else {
            while (cur < s.size() && s[cur] >= 'a' && s[cur] <= 'z')
                letter.top() += s[cur++];
        }
    }
    return letter.top();
}
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
    stack<int> s;
    int cur = 0;
    for (auto ch : pushed) {
        s.push(ch);
        while (!s.empty() && s.top() == popped[cur]) {
            s.pop();
            cur++;
        }
    }
    return s.empty();
}
int main()
{
    string s = decodeString("3[a]2[bc]");
    return 0;
}
